package com.yl.chainStore.control.company

import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.entity.company.SickCustomerAccessLogModel
import com.yl.chainStore.pojo.vo.company.SickCustomerAccessLogModelMoveByIdsVo
import com.yl.chainStore.pojo.vo.company.SickCustomerAccessLogModelMoveVo
import com.yl.chainStore.pojo.vo.company.SickCustomerAccessLogModelSelectVo
import com.yl.chainStore.pojo.vo.company.SickCustomerAccessLogModelUpdateStatusVo
import com.yl.chainStore.services.IWebCompanyDeptService
import com.yl.chainStore.services.sick.ISickCustomerAccessLogModelService
import com.yl.common.ErrorCode
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnError
import com.yl.common.control.returnSuccess
import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.interceptor.TransactionAspectSupport
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("company/accessLog/model")
open class CompanyAccessLogModelController(
    private val iWebCompanyDeptService: IWebCompanyDeptService,
    private val iSickCustomerAccessLogModelService: ISickCustomerAccessLogModelService
) {

    /**
     * 分页查询
     */
    @PostMapping("getPage")
    @Transactional
    open fun getPage(@RequestBody vo : SickCustomerAccessLogModelSelectVo):ResponseBody{
        return returnSuccess(iWebCompanyDeptService.getAccessLogModelPage(vo))
    }

    /**
     * 移动模版位置
     */
    @PostMapping("moveModel")
    @Transactional
    open fun moveModel(@RequestBody vo : SickCustomerAccessLogModelMoveVo):ResponseBody{
        val move = iSickCustomerAccessLogModelService.move(vo.id, vo.moveType, vo)
        if(move.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return move
        }
        return returnSuccess()
    }

    /**
     * 移动模版位置
     */
    @PostMapping("moveModelByIds")
    @Transactional
    open fun moveModelByIds(@RequestBody vo : SickCustomerAccessLogModelMoveByIdsVo):ResponseBody{
        val moveByIds = iSickCustomerAccessLogModelService.moveByIds(vo.ids)
        if(moveByIds.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return moveByIds
        }
        return returnSuccess()

    }

    /**
     * 修改启用状态
     */
    @PostMapping("updateStatus")
    @Transactional
    open fun updateStatus(@RequestBody vo : SickCustomerAccessLogModelUpdateStatusVo):ResponseBody{

        val updateStatus = iSickCustomerAccessLogModelService.updateStatus(vo.id, vo.status)
        if(updateStatus.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return updateStatus
        }
        return returnSuccess()
    }

    /**
     * 获取单个明细
     */
    @GetMapping("getModelDetail/{id}")
    @Transactional
    open fun getModelDetail(@PathVariable id : Long):ResponseBody{
        val model = iSickCustomerAccessLogModelService.getModelInfo(id)?:return returnError(ErrorCode.DATA_IS_NOT_FIND,"未找到模版")
        iSickCustomerAccessLogModelService.setDetails(model)
        return returnSuccess(model)
    }

    /**
     * 添加模版
     */
    @PostMapping("addModel")
    @Transactional(rollbackFor = [Exception::class])
    open fun addModel(@RequestBody model : SickCustomerAccessLogModel):ResponseBody{
        val createAccessLogModel = iWebCompanyDeptService.createAccessLogModel(model)

        if(createAccessLogModel.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return createAccessLogModel
        }
        return returnSuccess()
    }

    /**
     * 修改模版
     */
    @PostMapping("updateModel")
    @Transactional(rollbackFor = [Exception::class])
    open fun updateModel(@RequestBody model : SickCustomerAccessLogModel):ResponseBody{
        val updateModel = iSickCustomerAccessLogModelService.updateModel(model)
        if(updateModel.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return updateModel
        }
        return returnSuccess()
    }

    /**
     * 删除模板
     */
    @PostMapping("delModel/{id}")
    @Transactional(rollbackFor = [Exception::class])
    open fun delModel(@PathVariable id: Long):ResponseBody{
        val delAccessLogModel = iWebCompanyDeptService.delAccessLogModel(id)
        if(delAccessLogModel.bodyIsError()){
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
            return delAccessLogModel
        }
        return returnSuccess()
    }


    /**
     * 创建医生类型
     */
    @GetMapping("getDoctorType")
    open fun getDoctorType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_FIRST_SICK_DOCTOR.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_SICK_DOCTOR.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_RESPONSIBILITY_FOR_THE_DOCTOR.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_OTHER_DOCTOR.getMap())
        return returnSuccess(resList)
    }

    /**
     * 创建随访人类型
     */
    @GetMapping("getDealUserType")
    open fun getDealUserType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_FIRST_SICK_CONSULTANT.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_SICK_CONSULTANT.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_CONSULTANT.getMap())
//        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_NET_CONSULTANT.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_OTHER.getMap())
        return returnSuccess(resList)
    }

    /**
     * 模版创建类型
     */
    @GetMapping("getCreateType")
    open fun getCreateType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CREATE_TYPE_CREATE_ALL.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CREATE_TYPE_CREATE_BY_LAST_OVER.getMap())
        return returnSuccess(resList)
    }

    /**
     * 模版时间类型
     */
    @GetMapping("getTimeType")
    open fun getTimeType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_TIME_TYPE_DAY.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_TIME_TYPE_WEEK.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_TIME_TYPE_MONTH.getMap())
        return returnSuccess(resList)
    }

    /**
     * 模版时间类型
     */
    @GetMapping("getMoveType")
    open fun getMoveType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.MOVE_TYPE_UP.getMap())
        resList.add(TypeEnum.MOVE_TYPE_DOWN.getMap())
        return returnSuccess(resList)
    }

    /**
     * 模版时间类型
     */
    @GetMapping("getCreateTimeType")
    open fun getCreateTimeType():ResponseBody{
        val resList = mutableListOf<Map<String,Any>>()
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CREATE_TIME_INTERVAL_TYPE_FIRST.getMap())
        resList.add(TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CREATE_TIME_INTERVAL_TYPE_FIRST.getMap())
        return returnSuccess(resList)
    }








}